
<?php
	include 'func/addPar.php';
	include 'func/sql.php';
	include 'func/check.php';
	include 'func/get.php';
	include 'func/mail.php';
	
	$sn = intval($_POST['sn']);
	
	if($sn != null && $_POST['event'] != ""){

		$event = $_POST['event'];

		$name = "";
		
		if(isset($_POST['name'])){
			$name = $_POST['name'];
		}
		
//		if($name == null || $name == ""){
//			header('Location: index.php?error=' . urlencode("Du skal angive et navn!!"));
//		}
		
		if(isset($_POST['notMem'])){
			echo "NOT MEMBER";
			addPendingMember($sn,$name);
		}
		
		$r = addPar($event,$sn,$name);
		
		$name = checkSN($sn);
		$pname = checkSN($sn,true);
		if(!$name){
			$name = $pname;
		}
		
		switch($r){
			case 0:
				//NOT MEMBER
				header('Location: index.php?error=0&sn=' . $sn . '&event=' . $event);
			break;
			case 1:
				//NO EVENT ID = $event
				header('Location: index.php?error=1&event=' . $event);
			break;
			case 2:
				//IS ON LIST
				header('Location: index.php?error=2&event=' . $event);
			break;
			case 3:
				//IS NOW ON LIST!
				header('Location: index.php?added=' . $name . '&event=' . $event);
			break;
			case 4:
				//IS NOW ON WAITLIST!
				header('Location: index.php?added=' . $name . '&event=' . $event . '&to=wl');
			break;
			case 5:
				//IS ALREADY ON WAITLIST!
				header('Location: index.php?error=3&event=' . $event);
			break;
		}
		
	}else{
		header('Location: index.php?error=shit');
	}
	
	
?>